package com.runda.biz.controller;

import java.util.List;

import javax.annotation.Resource;

import com.bbjob.dto.Result;
import com.bbjob.model.ProductAdapterInfo;
import com.runda.biz.service.IProductAdaptionInfoService;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("production/adaptionInfo")
public class ProductAdaptionInfoController{
    @Resource
    private IProductAdaptionInfoService adaptionInfoService;
    @PostMapping("list/save/{productId}")
    public Result<String> saveBatch(@RequestBody List<ProductAdapterInfo> infoList,@PathVariable("productId") Integer id){
        int ok=this.adaptionInfoService.saveBatch(infoList, id);
        if(ok > 0)
        return new Result<String>();
        return new Result<String>(5000,"未知原因保存失败,请联系管理员");
    }
    @GetMapping(value="list/{productId}")
    public Result<List<ProductAdapterInfo>> getAdaptionInfoList(@PathVariable("productId") Integer productId){
        List<ProductAdapterInfo> list=this.adaptionInfoService.selectByProperty("productId", productId, ProductAdapterInfo.class);
        return new Result<List<ProductAdapterInfo>>(list);
    }
    @GetMapping(value="del/{productId}")
    public Result<String> delAdaptionInfo(@PathVariable("productId") Integer productId){
        ProductAdapterInfo record=new ProductAdapterInfo();
        record.setId(productId);
        int ok=this.adaptionInfoService.delBy(record);
        if(ok > 0)
        return new Result<String>();
        return new Result<String>(5000,"未知原因保存失败,请联系管理员");
    }
    @PostMapping("save/{productId}")
    public Result<String> save(@PathVariable("productId") Integer productId, @RequestBody ProductAdapterInfo adaptionInfo) {
        adaptionInfo.setProductId(productId);
        int ok=this.adaptionInfoService.save(adaptionInfo);
        if(ok > 0)
        return new Result<String>();
        return new Result<String>(5000,"未知原因保存失败,请联系管理员");
    }
}